package com.macro.mall.tiny.security.config;

import com.macro.mall.tiny.security.interceptor.TokenInterceptor;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author Tyrone
 * @date 2024/10/15 00:19
 */
@Configuration
public class ApplicationConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Value("${portal.urls:[]}")
    private List<String> portalUrls;

    @Value("${portal.enable:false}")
    private Boolean enableTokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(tokenInterceptor);
        if (enableTokenInterceptor) {
            interceptorRegistration.addPathPatterns(portalUrls);
        }
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
